//---------------------------------------------------------------------
// Author: Keith Hill
//
// Description: Class to implement the Convert-ToBase64 cmdlet.
//
// Creation Date: Aug 20, 2006
//---------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Management.Automation;

namespace Pscx.Commands.Text
{
    [Cmdlet(VerbsData.ConvertTo, "Base64"),
     Description("Converts byte array to base64 string."),
     RelatedLinks("ConvertFrom-Base64")]
    public class ConvertToBase64Command : Cmdlet
    {
        private List<byte> _bytes = new List<byte>();

        [AllowEmptyCollection, AllowNull,
         Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true, ValueFromPipelineByPropertyName = true,
                   HelpMessage="Byte array to be encoded into base64 string.")]
        public byte[] Bytes
        {
            get { return _bytes.ToArray(); }
            set { _bytes.AddRange(value); }
        }

        protected override void EndProcessing()
        {
            string base64 = Convert.ToBase64String(_bytes.ToArray());
            WriteObject(base64);
        }
    }
}
